﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HRC.Library.ContextFoundation;
using Lehnet.BusinessLayer;
using Lehnet.BusinessLayer.Interfaces;

namespace Lehnet.WebUI.Controllers
{
    public class IlController : Controller
    {
        //
        // GET: /Il/

        #region Login
        public ActionResult Index()
        {
            return View();
        }

        [ChildActionOnly]
        public PartialViewResult IlListele()
        {
            var ib = ProxyHelper<IlBusiness, IIlBusiness>.Instance.AddOrGet();
            List<Models.Il> ilList = ib.LoadAll();
            return PartialView(ilList);
        }
        #endregion

        #region Create
        public ActionResult Olustur()
        {
            return View();
        }

        [ChildActionOnly]
        public PartialViewResult Create()
        {
            return PartialView(new Models.Il());
        }

        [HttpPost]
        public PartialViewResult Create(Models.Il il)
        {
            try
            {
                var ib = ProxyHelper<IlBusiness, IIlBusiness>.Instance.AddOrGet();
                ib.SaveOrUpdate(il);

                ViewBag.ResultMessage = "Kayıt başarılı";
                ControllerContext.HttpContext.Response.Redirect("Index");
            }
            catch (Exception exp)
            {
                ViewBag.ResultMessage = "Kaydedilemedi: " + exp.Message;
            }

            return PartialView();
        }
        #endregion
    }
}
